import Vue from 'vue'
import App from './App.vue'
import router from './router'

import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';

import axios from 'axios'  //axios.js
//axios 请求拦截器给每个请求加上请求头
axios.interceptors.request.use(
  config =>{
    //给请求携带请求头
    let token = localStorage.getItem("authorization");
  if(token){
    config.headers.authorization = token
  }
  return config
  }
)
axios.interceptors.response.use(
  resp =>{
    if(resp.data.code ==2001){
      router.push({path:"/login"})
    }
    if(resp.data.code ==500){
      //跳到一个页面
    }
    return resp;

  }
)



Vue.prototype.$axios = axios //把axios 配置成全局 所有组件都可以用了

Vue.use(ElementUI);

Vue.config.productionTip = false

new Vue({
  router,
  render: h => h(App)
}).$mount('#app')
